/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package classcreator.DB;

import classcreator.ClassCreator;
import com.mysql.jdbc.Connection;
import java.sql.DriverManager;
import java.util.logging.Level;
import java.util.logging.Logger;

public class DataBaseConnFactory {

    private static DataBaseConnFactory instance = new DataBaseConnFactory();
    private String userName;
    private String MySQLurl;
    private String password = "";

    
    static{
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(DataBaseConnFactory.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void assignValues(String url) {
        this.userName = "root";
        this.MySQLurl = "jdbc:mysql://localhost/" + url;
    }

    public static DataBaseConnFactory getInstance() {
        return DataBaseConnFactory.instance;
    }

    public Connection obtenerConnexion() throws Exception {
        assignValues("test");
        Connection connection = null;
        connection = (Connection) DriverManager.getConnection(this.MySQLurl, userName, password);
        return connection;
    }

    public Connection obtenerNewConexion() throws Exception {
        assignValues(ClassCreator.getInstance().getPackagename());
        Connection connection = (Connection) DriverManager.getConnection(this.MySQLurl, userName, password);
        return connection;
    }
}
